
.text
.global _start
_start:
    bl close_watch_dog
    bl init_mem_sdram
    bl copy_code_from_sram2sdram
    ldr pc, =run_on_sdram

run_on_sdram:
    ldr sp, =0x34000000
    bl main

halt_loop:
    b halt_loop

close_watch_dog:
    ldr r0, =0x53000000 @watch dog address
    mov r1, #0x0
    str r1, [r0]
    mov pc, lr

init_mem_sdram:
    ldr r0, =0x48000000 @BWSCON address
    ldr r1, =0x22011110
    str r1, [r0]

    ldr r0, =0x48000004 @BANKCON0
    mov r1, #0x700
    str r1, [r0]

    ldr r0, =0x48000008 @BANKCON1
    mov r1, #0x700
    str r1, [r0]

    ldr r0, =0x4800000c @BANKCON2
    mov r1, #0x700
    str r1, [r0]

    ldr r0, =0x48000010 @BANKCON3
    mov r1, #0x700
    str r1, [r0]

    ldr r0, =0x48000014 @BANKCON4
    mov r1, #0x700
    str r1, [r0]

    ldr r0, =0x48000018 @BANKCON5
    mov r1, #0x700
    str r1, [r0]


    ldr r0, =0x4800001c @BANKCON6
    ldr r1, =0x00018005
    str r1, [r0]

    ldr r0, =0x48000020 @BANKCON7
    ldr r1, =0x00018005
    str r1, [r0]

    ldr r0, =0x48000024 @REFRESH
    ldr r1, =0x008c07A3
    str r1, [r0]

    ldr r0, =0x48000028 @BANKSIZE
    mov r1, #0xB1
    str r1, [r0]

    ldr r0, =0x4800002C @MRSRB6
    mov r1, #0x30
    str r1, [r0]

    ldr r0, =0x48000030 @MRSRB7
    mov r1, #0x30
    str r1, [r0]

    mov pc, lr

copy_code_from_sram2sdram:
    mov r0, #0             @start of source sram
    mov r1, #4096        @copy size
    mov r2, #0x30000000    @target address
1:
    ldr r3, [r0], #4
    str r3, [r2], #4
    cmp r1, r0
    bne 1b
    mov pc, lr
